//
//  YYMessageVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/10.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYMessageVC.h"
#import "YYMessageCell.h"

@interface YYMessageVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray * dataArr;

@end

@implementation YYMessageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.pageNO = 1;
        [self.dataArr removeAllObjects];
        [self getData];
    }];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        self.pageNO++;
        [self getData];
    }];
}

- (void)getData {
    
    [RequestOperationManager personalMessage_page:self.pageString success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            NSArray * array = result[@"data"][@"data"];
            [self.dataArr addObjectsFromArray:array];
            if (self.dataArr.count == 0) {
                self.baseLabel.text = @"暂无消息";
                self.baseImageView.hidden = NO;
            }else{
                [self.tableView reloadData];
            }
            if (array.count == 0) {
                   [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                   [self.tableView.mj_footer endRefreshing];
            }
        }else{
            [self.tableView.mj_footer endRefreshing];

        }
        [self.tableView.mj_header endRefreshing];
        
    } failture:^(NSError *error) {
        
    }];
 
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYMessageCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYMessageCell"];
    NSDictionary * dic = self.dataArr[indexPath.row];
    cell.lbContent.text = dic[@"content"];
    cell.lbDate.text = [DateUtil getDateWithTimeInterval:dic[@"add_time"] type:@"YYYY-MM-dd HH:mm:ss"];
    return cell;
}

-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArr;
}
@end
